package cn.wjh.business.controller;

import cn.wjh.business.domain.AuthRecord;
import cn.wjh.business.service.IAuthRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 认证记录Controller
 *
 * @author jiraWu
 * @date 2023-10-27
 */
@RestController
@RequestMapping("/business/authRecord")
public class AuthRecordController extends BaseController {
	@Resource
	private IAuthRecordService authRecordService;

	/**
	 * 查询认证记录列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:authRecord:list')")
	@GetMapping("/list")
	public TableDataInfo list(AuthRecord authRecord) {
		startPage();
		List<AuthRecord> list = authRecordService.selectAuthRecordList(authRecord);
		return getDataTable(list);
	}

	/**
	 * 导出认证记录列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:authRecord:export')")
	@Log(title = "认证记录", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, AuthRecord authRecord) {
		List<AuthRecord> list = authRecordService.selectAuthRecordList(authRecord);
		ExcelUtil<AuthRecord> util = new ExcelUtil<AuthRecord>(AuthRecord.class);
		util.exportExcel(response, list, "认证记录数据");
	}

	/**
	 * 获取认证记录详细信息
	 */
//	@PreAuthorize("@ss.hasPermi('business:authRecord:query')")
	@GetMapping(value = "/{authRecordId}")
	public AjaxResult getInfo(@PathVariable("authRecordId") Long authRecordId) {
		return success(authRecordService.selectAuthRecordByAuthRecordId(authRecordId));
	}
	/*根据用户Id和审核状态查询认证资料*/
	@GetMapping(value = "/review")
	public AjaxResult getInfoByUserIdAndStatus() {
		return success(authRecordService.getInfoByUserIdAndStatus());
	}

	/*审核认证资料*/
	@PutMapping(value = "/review")
	public AjaxResult review(@RequestBody AuthRecord authRecord) {
		return success(authRecordService.review(authRecord));
	}




	/**
	 * 新增认证记录
	 */
//	@PreAuthorize("@ss.hasPermi('business:authRecord:add')")
	@Log(title = "认证记录", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody AuthRecord authRecord) {
		return toAjax(authRecordService.insertAuthRecord(authRecord));
	}

	/**
	 * 修改认证记录
	 */
//	@PreAuthorize("@ss.hasPermi('business:authRecord:edit')")
	@Log(title = "认证记录", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody AuthRecord authRecord) {
		return toAjax(authRecordService.updateAuthRecord(authRecord));
	}

	/**
	 * 删除认证记录
	 */
//	@PreAuthorize("@ss.hasPermi('business:authRecord:remove')")
	@Log(title = "认证记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{authRecordIds}")
	public AjaxResult remove(@PathVariable Long[] authRecordIds) {
		return toAjax(authRecordService.deleteAuthRecordByAuthRecordIds(authRecordIds));
	}
}
